# -*- coding: utf-8 -*-

# Define here the models for your spider middleware
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/spider-middleware.html

from scrapy import signals
from fake_useragent import UserAgent
import random

class UserAgentDownloadMiddleware(object):

    def process_request(self,request,spider):
        user_agent = UserAgent()
        request.headers['User-Agent'] = user_agent.random


class IPProxyDownloadMiddleware(object):

    Proxy = [{'ip':'182.46.214.250','port':9999,'expire_time':'	2020-07-03 17:31:01'},
             {'ip':'113.195.17.111','port':9999,'expire_time':'	2020-07-03 16:31:01'}]
    def process_request(self,request,spider):
        proxy = random.choice(self.Proxy)
        request.meta['proxy'] = 'http://' + proxy['ip'] + ':' + str(proxy['port'])